package com.ruoyi.web.controller.sincerity;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SinDeed;
import com.ruoyi.system.service.ISinDeedService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 事迹分值Controller
 *
 * @author buke
 * @date 2023-03-10
 */
@RestController
@RequestMapping("/system/deed")
public class SinDeedController extends BaseController
{
    @Autowired
    private ISinDeedService sinDeedService;




    /**
     * 查询事迹分值列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SinDeed sinDeed)
    {
        startPage();

        List<SinDeed> list = sinDeedService.selectSinDeedList(sinDeed);
        for (SinDeed deed : list) {
            deed.setParentDescribe(StringUtils.isBlank(deed.getParentDescribe()) ? "父类" : deed.getParentDescribe());
        }
        return getDataTable(list);
    }

    /**
     * 导出事迹分值列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, SinDeed sinDeed)
    {
        List<SinDeed> list = sinDeedService.selectSinDeedList(sinDeed);
        ExcelUtil<SinDeed> util = new ExcelUtil<SinDeed>(SinDeed.class);
        util.exportExcel(response, list, "事迹分值数据");
    }

    /**
     * 获取事迹分值详细信息
     */
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sinDeedService.selectSinDeedById(id));
    }

    /**
     * 新增事迹分值
     */
    @PostMapping
    public AjaxResult add(@RequestBody SinDeed sinDeed)
    {
        return toAjax(sinDeedService.insertSinDeed(sinDeed));
    }

    /**
     * 修改事迹分值
     */
    @PutMapping
    public AjaxResult edit(@RequestBody SinDeed sinDeed)
    {
        return toAjax(sinDeedService.updateSinDeed(sinDeed));
    }

    /**
     * 删除事迹分值
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sinDeedService.deleteSinDeedByIds(ids));
    }

    @GetMapping("/getChildDeed")
    public TableDataInfo getChildDeed(){
        startPage();
        List<SinDeed> list = sinDeedService.selectSinChildDeedList();
        for (SinDeed deed : list) {
            deed.setParentDescribe(StringUtils.isBlank(deed.getParentDescribe()) ? "父类" : deed.getParentDescribe());
        }
        return getDataTable(list);
    }

    /**
     * @author buke
     * 添加数据
     * */
    @GetMapping("/addData")
    public AjaxResult addData(){
	    sinDeedService.addData() ;
	    return success() ;
    }
}
